﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Web;
using FaceSharp.Api;
using FaceSharp.Api.Types;
using Types = FaceSharp.Api.Types;

namespace FaceSharp.Samples.WinForm
{
    public static class SessionInfo
    {
        public static string AccessToken;
        public static long UserId = 0;
        public static Types.User CurrentUser;
    }


    public class FacebookCore : IFacebookCore
    {
        private readonly string _applicationId;
        private readonly string _apiKey;
        private readonly string _applicationSecret;
        private readonly string _applicationUrl;
        private readonly string _extendedPermissions;

        public string AccessToken
        {
            get
            {
                return SessionInfo.AccessToken ?? "";
            }
            set
            {
                SessionInfo.AccessToken = value;
            }
        }
        public string ApplicationId { get { return _applicationId; } }
        public string ApiKey { get { return _apiKey; } }
        public string ApplicationSecret { get { return _applicationSecret; } }
        public string ApplicationUrl { get { return _applicationUrl; } }
        public string ExtendedPermissions { get { return _extendedPermissions; } }
        public DateTime SessionExpirationDate { get; set; }
        public long CurrentUserId
        {
            get
            {
                return SessionInfo.UserId;
            }
            set
            {
                SessionInfo.UserId = value;
            }
        }


        public Types.User CurrentUser
        {
            get { return SessionInfo.CurrentUser; }
            set
            {
                SessionInfo.CurrentUser = value;
            }
        }

        private string _code;
        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }

        private DateTime? _accessTokenExpirationDate;
        public DateTime? AccessTokenExpirationDate
        {
            get { return _accessTokenExpirationDate; }
            set { _accessTokenExpirationDate = value; }
        }

        private SignedRequest _signedRequest;
        public SignedRequest SignedRequest
        {
            get { return _signedRequest; }
            set { _signedRequest = value; }
        }


        public void UserAuthenticated()
        {
            // do nothing, we aren't using this.
        }

        public FacebookCore()
        {
            _applicationId = ConfigurationManager.AppSettings["ApplicationId"];
            _apiKey = ConfigurationManager.AppSettings["ApiKey"];
            _applicationSecret = ConfigurationManager.AppSettings["ApplicationSecret"];
            _applicationUrl = ConfigurationManager.AppSettings["ApplicationUrl"];
            _extendedPermissions = ConfigurationManager.AppSettings["ExtendedPermissions"];
        }
    }
}